﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;

using EHTWebsiteProject.Code.BLL;
using EHTWebsiteProject.Code.Entity;
using EHTWebsiteProject.Code.Utility;
using EHTWebsite.Code;

namespace EHTWebsiteProject
{
    public partial class HistoryOrders : System.Web.UI.Page
    {
        string CustomerID = "";
       
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser theUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            if (theUser == null)
                Response.Redirect("Index.aspx");
            else
            CustomerID = theUser.ProviderUserKey.ToString();
            Int32 orderSate = HangSo.ORDER_STATE_APPENDING;
            try
            {
                orderSate = Int32.Parse(Request.QueryString["OrderState"].ToString());
            }
            catch (Exception ex)
            {
                orderSate = HangSo.ORDER_STATE_APPENDING;
            }
            

            if (!Page.IsPostBack)
            {
                
                LoadDataOrders(orderSate, CustomerID);
            }
        }

        public void SetColor(Int32 OrderState)
        {
            string str = "";
            if (OrderState == 1)
            { 
                str="<script type='text/javascrip'> $(document).ready(funtion(){$('#Order_1').addClass('current')})</script>";
            }
             if (OrderState == 2)
            { 
                str="<script type='text/javascrip'> $(document).ready(funtion(){$('#Order_2').addClass('current')})</script>";
            }
             if (OrderState == 3)
            { 
                str="<script type='text/javascrip'> $(document).ready(funtion(){$('#Order_3').addClass('current')})</script>";
            }
             if (OrderState == -1)
            { 
                str="<script type='text/javascrip'> $(document).ready(funtion(){$('#Order_4').addClass('current')})</script>";
            }
             Page.RegisterClientScriptBlock("ClientScript", str.ToString());
        }

        protected void grdData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }
        private void LoadDataOrders(Int32 OrderSate, String CustomerID)
        {
            try
            {
                DataSet dsOrder = OrderProvider.GetOrdersForOrderState(CustomerID, OrderSate);
                this.grdData.DataSource = dsOrder;
                this.grdData.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            
        }
    }
}